from .dl_config import *
from .dl_single import dl_single
from .dl_many import dl_multi_download


class download_manager(object):
	def __init__(self, urls):
		self.urls = urls
		logging.info(json.dumps(urls))
	
	def set_urls(self, urls):
		self.urls = urls
	
	def set_local_path(self, path):
		"""
		指定下载目录
		:param path: 给定的下载目录
		:return: None
		"""
		config_path(path)
	
	def start_download(self):
		length = len(self.urls)
		if length < 0:
			logging.error('请添加下在文件链接')
			return
		if length == 1:
			dl = dl_single(self.urls)
			dl.dl_start()
		else:
			dl = dl_multi_download(self.urls)
			dl.dl_start()


if __name__ == '__main__':
	urls = ['https://img30.360buyimg.com/sku/jfs/t1/194009/31/6077/212849/60b60471E05ea0f2e/f4cd241f774db151.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/176374/10/12436/251494/60b603adE7710bca7/ab21049a61b65585.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/172874/13/12422/160821/60b603adE4ff72514/c2c6fa93bb49d2cf.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/178492/9/7067/296630/60b603adE76704315/6897699d152206ae.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/188735/15/5960/124502/60b603adEc1616e02/f80f68ff3734cfed.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/176254/14/12359/330943/60b603adE84eeb9b3/c0e01fcc39989dee.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/190906/8/6025/323693/60b603adEe1ffbbec/c0da91b0a104a0f7.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/185473/14/7019/353192/60b603adE0054fad6/b3c528a5ebedbbfa.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/196789/33/5902/269998/60b603adE7b6ba0d8/cf0bfc2765e92cee.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/178160/33/6930/319712/60b603adE8458bcd3/e513004c10ad3411.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/193959/11/5952/273374/60b603adE3839e921/3cee002ae16da075.jpg',
	        'https://img30.360buyimg.com/sku/jfs/t1/106792/6/17763/89068/5e8d8094Ebe7d6d06/dcfcdae4e10ab64c.jpg']
	logging.info(json.dumps(urls))
	manager = download_manager(urls)
	manager.set_local_path('/Users/farben/Downloads')
	manager.start_download()
